﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Shapes;

namespace Wintellect.LiveFx.Cloudboard
{
  /// <summary>
  /// Interaction logic for CloudboardDetails.xaml
  /// </summary>
  public partial class CloudboardDetails : Window
  {
    private Clipboard clipboard;

    public CloudboardDetails(Clipboard clipboard)
    {
      InitializeComponent();
      this.clipboard = clipboard;

      if (this.clipboard != null)
      {
        this.name.IsEnabled = false;
        this.name.Text = this.clipboard.Name;
        this.description.Text = this.clipboard.Description;
      }
    }

    private void ok_Click(object sender, RoutedEventArgs e)
    {
      this.OpenOrCreateClipboard();

      this.DialogResult = true;
      this.Close();
    }

    private void OpenOrCreateClipboard()
    {
      // Create/Update the clipboard
      if (this.clipboard == null)
      {
        this.clipboard = new Clipboard(this.name.Text);
      }
      else
      {
        this.clipboard.Description = this.description.Text;
      }
      this.clipboard.Description = this.description.Text;

      this.clipboard.Update();
    }

    private void cancel_Click(object sender, RoutedEventArgs e)
    {
      this.DialogResult = false;
      this.Close();
    }

    private void permissions_Click(object sender, EventArgs e)
    {
      this.OpenOrCreateClipboard();

      ManagePermissions permissionsDialog = new ManagePermissions(this.clipboard);
      permissionsDialog.Owner = this;
      permissionsDialog.ShowDialog();
    }
  }
}
